﻿using RStudio.UIFramwork.Pool;
using System;
using UnityEngine;



namespace RStudio.UIFramwork.Utils
{
    /// <summary>
    /// UI配件属性工厂
    /// </summary>
    public class UIComponentFactoryUtil
    {
        /// <summary>
        /// 
        /// </summary>
        public static GameObject GetMask()
        {
            Type type = typeof(UIMask);

            var unitPool = UnitPoolCenter.Get(type);
            if (unitPool == null)
            {
                UIModuleCenter.Instance.UIModuleInstance.PreLoad(type);
                unitPool = UnitPoolCenter.Get(type);
            }
            GameObject target = unitPool.Get();
            target.GetComponent<UIMask>().InitComponent();

            return target;
        }

        /// <summary>
        /// 
        /// </summary
        public static GameObject GetBlock()
        {
            Type type = typeof(UIBlock);

            var unitPool = UnitPoolCenter.Get(type);
            if (unitPool == null)
            {
                UIModuleCenter.Instance.UIModuleInstance.PreLoad(type);
                unitPool = UnitPoolCenter.Get(type);
            }
            GameObject target = unitPool.Get();
            target.GetComponent<UIBlock>().InitComponent();

            return unitPool.Get();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static GameObject GetAreaQuit()
        {
            Type type = typeof(UIAreaQuit);

            var unitPool = UnitPoolCenter.Get(type);
            if (unitPool == null)
            {
                UIModuleCenter.Instance.UIModuleInstance.PreLoad(type);
                unitPool = UnitPoolCenter.Get(type);
            }
            GameObject target = unitPool.Get();
            target.GetComponent<UIAreaQuit>().InitComponent();

            return target;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="gameObject"></param>
        public static void Recycle<T>(GameObject @gameObject)
        {
            var pool = UnitPoolCenter.Get(typeof(T));
            pool.Recycle(@gameObject);
        }
    }
}
